<?
/**
* PROJECT FRAMEWORK
* PROJECT FOR CONTROLING CLASSES AND OTHER STUFF
* LOTS OF DESCRIPTION CAN COME IN HERE. AS LONG AS IT MAKES SENSE OFCOURSE
* 
* @link http://afirma.doutromundo.com
* @copyright Copyright: DM
* @author Gregory Brown 
* @access public
* @package framework
*/
/**
* MODULE: CATEGORIES
* This is where the main every day functions and objects for FW are determined.
* This is where the main every day functions and objects for FW are determined.
* This is where the main every day functions and objects for FW are determined.
* 	
* @package framework
* @version 1.0
* @uses DM
*/
include("../../../resource/classes/core/dm.class.php");
class categories extends DM{
	/**
	* ID
	*@var int
	*/
	var $id_cateogry;
	/**
	* Category Name
	*@var varchar
	*/
	var $txt_name;
	/**
	* Status
	*@var bit
	*/
	var $abit_stat;
	/**
	* Status
	*@var bit
	*/
	var $bbitw_stat;
	/**
	* Status
	*@var bit
	*/
	var $bcit_stat;
	/**
	* Status
	*@var bit
	*/
	var $dbit_stat;
	/**
	* Toggle debugging state for object
	*@var boolean/bit
	*/
	var $debugging=false;
	/**
	* List where SQL resultSet will be stored
	*@var array
	*/
	var $list;

	/**
	*	Constructor class.
	*	@return Stirng
	*/
	function cls_categories(){
		//LOAD THE DATABSE CLASS
		$this->loadClass('database','database');
		//INITIALIZE THE VARIABLES
		$this->id_cateogry = '';
		$this->txt_name = '';
		$this->abit_stat = '';
		$this->bbitw_stat = '';
		$this->bcit_stat = '';
		$this->dbit_stat = '';
		$this->lista = array();
		$this->debugging=false;
	}
	/**
	*	Fetch a single object using the key.
	*	@return Stirng
	*/
	function get(){
		//SQL STRING
		$sql="SELECT * FROM tbl_categories WHERE id_cateogry='$this->id_cateogry'";
		$db= new database();
		$db->debugging=$this->debugging;
		if ($db->connect()){
			if ($db->fetchSingle($sql)){
				$this->id_cateogry=$db->resultArray['id_cateogry'];
				$this->txt_name=$db->resultArray['txt_name'];
				$this->abit_stat=$db->resultArray['abit_stat'];
				$this->bbitw_stat=$db->resultArray['bbitw_stat'];
				$this->bcit_stat=$db->resultArray['bcit_stat'];
				$this->dbit_stat=$db->resultArray['dbit_stat'];
				return $this->watch(true,$db,'get_single');
			}else{
				$this->errorReport('Error in the select',$sql);
				return $this->watch(false,$db,"get_List - $sql");
			}
		}else{
			$this->errorReport('Could not conncet to the database',$db);
			return $this->watch(false,$db,'get_single');
		}
	}
	/**
	*	Get the list of objects from the DB.
	*	@return Stirng
	*/
	 function getList(){
		//SQL STRING
		$sql="SELECT * FROM tbl_categories";
		$db= new database();
		$db->debugging=$this->debugging;
		if ($db->connect()){
			if ($db->fetch($sql)){
				$this->lista=$db->resultArray;
				return $this->watch(true,$db,'get_list');
			}else{
				$this->errorReport('Error in the select',$sql);
				return $this->watch(false,$db,"get_List - $sql");
			}
		}else{
			$this->errorReport('Could not conncet to the database',$db);
			return $this->watch(false,$db,'get_list');
		}
	}
	/**
	*	Save current Object (update if key is not Null).
	*	@return Stirng
	*/
	 function save(){
		//SQL STRING - CHECK KEY TO SEE IF WE USE INSERT OR UPDATE
		if ($this->id_cateogry==''){
			$sql="INSERT INTO tbl_categories(
				id_cateogry, 
				txt_name, 
				abit_stat, 
				bbitw_stat, 
				bcit_stat, 
				dbit_stat
			)VALUES(
				'".$this->id_cateogry."', 
				'".$this->txt_name."', 
				'".$this->abit_stat."', 
				'".$this->bbitw_stat."', 
				'".$this->bcit_stat."', 
				'".$this->dbit_stat."'
			)";
		}else{
			$sql="UPDATE tbl_categories SET 
				id_cateogry='".$this->id_cateogry."', 
				txt_name='".$this->txt_name."', 
				abit_stat='".$this->abit_stat."', 
				bbitw_stat='".$this->bbitw_stat."', 
				bcit_stat='".$this->bcit_stat."', 
				dbit_stat='".$this->dbit_stat."'
			";
		}
		$db= new database();
		$db->debugging=$this->debugging;
		if ($db->connect()){
			if ($db->execute($sql)){
				return $this->watch(true,$db,'save_item');
			}else{
				$this->errorReport('Error in the select',$sql);
				return $this->watch(false,$db,"save_item - $sql");
			}
		}else{
			$this->errorReport('Could not conncet to the database',$db);
			return $this->watch(false,$db,'save_item');
		}
	}
	/**
	*	Delete element from DB using primary key.
	*	@return Stirng
	*/
	 function delete(){
		//SQL STRING
		$sql="DELETE FROM tbl_categories WHERE id_cateogry='$this->id_cateogry'";
		$db= new database();
		$db->debugging=$this->debugging;
		if ($db->connect()){
			if ($db->execute($sql)){
				return $this->watch(true,$db,'delete_item');
			}else{
				$this->errorReport('Error in the select',$sql);
				return $this->watch(false,$db,"delete_item - $sql");
			}
		}else{
			$this->errorReport('Could not conncet to the database',$db);
			return $this->watch(false,$db,'delete_item');
		}
	}
}

?>